﻿using RabbitMQ.Client;
using System.Configuration;
using System.Text;

namespace LaserAutoTest.Common.RabbitMqs
{
    public class RabbitClient
    {
        private static IModel channel = Channels.Channel;
        private static readonly string routingKey = ConfigurationManager.AppSettings["RoutingKey"];

        public static void PublishMessage(string message)
        {
            byte[] body = Encoding.UTF8.GetBytes(message);
            channel.BasicPublish(Channels.Exchange, routingKey, null,body);
        }

        public static void BindingQueue(string queueName, string routingKey = "RoutingKey1")
        {
            channel.QueueDeclare(queueName, false, false, false);
            channel.QueueBind(queueName, Channels.Exchange, routingKey);// 将队列与交换机绑定
            channel.BasicQos(0, 1, false);// 告诉Rabbit每次只能向消费者发送一条信息,再消费者未确认之前,不再向他发送信息
        }
    }
}